<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-刊例录入页</title>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="<%=path%>/js/My97DatePicker/WdatePicker.js"></script>
		<link type="text/css"
			href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css"
			rel="stylesheet" />
		<script type="text/javascript"
			src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
	<script type="text/javascript">
	$(document).ready(function(){  
   //禁止退格键 作用于Firefox、Opera    
    document.onkeypress = banBackSpace;  
   //禁止退格键 作用于IE、Chrome   
	  document.onkeydown = banBackSpace;  
	});
	//处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外 
function banBackSpace(e){
	//alert(event.keyCode)
    var ev = e || window.event;//获取event对象   
    var obj = ev.target || ev.srcElement;//获取事件源     
    var t = obj.type || obj.getAttribute('type');//获取事件源类型     
    //获取作为判断条件的事件类型 
    var vReadOnly = obj.readOnly;
    var vDisabled = obj.disabled;
    //处理undefined值情况 
    vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
    vDisabled = (vDisabled == undefined) ? true : vDisabled;
    //当敲Backspace键时，事件源类型为密码或单行、多行文本的，  
    //并且readOnly属性为true或disabled属性为true的，则退格键失效  
    var flag1 = ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vDisabled == true);
    //当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效    
    var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";
    //判断    
    if (flag2 || flag1) 
        event.returnValue = false;//这里如果写 return false 无法实现效果 
}
</script>
<script type="text/javascript">
	function exist(id){//判断元素ID是否存在
    var s=document.getElementById(id);
    if(s){return true}
    	else{return false}
    }
	
	function getLen(str){
		var len=0;
		if(null!=str&&str!=""){
			for(var i=0;i<str.length;i++){
				var intCode=str.charCodeAt(i);
				//如果ASCII码等于34(")38(&)39(')47(/)60(<)62(>)92(\)也算三个字符
				if (intCode>=0&&intCode<=127&&intCode!=34&&intCode!=39&&intCode!=47&&intCode!=60&&intCode!=62&&intCode!=92){
					len=len+1;
				}else{
					len=len+3;
				}
			}
		}
		return len;
	}
	
	function trim(str) {//去掉空格
	var str1 = $.trim(str);
	return str1;
	}
	function doAdd(url){
		var msgName = "0";
		var msgAlert = "2";//正确
		var mediumPriceAlert ="2";
		var mediumAbilityAlert="2";
		var surchargesRatioAlert = "2";
		var mediumName = document.getElementById("mediumName_01").value;
		var pattern = /[^\d\.]/g;
		var contractNum = /^[\w-\s]+$/;
		var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;
		var num = new RegExp("^[0-9]*$");
		
       if ($.trim(mediumName) == '') {
		alert('刊例名称不能为空！');
			document.getElementById('mediumName_01').focus();
			msgName = "1";
			return false;
		}else if (!myReg.test(mediumName)) {
			alert("刊例名称不能包含：“$、#、%、/、*、<、>、'、\"、\\、& ”等特殊字符，请重新输入！");
			document.getElementById('mediumName_01').focus();
			msgName = "1";
			return false;
		}else if (getLen(mediumName) > 150) {
			alert("刊例名称应不大于50个汉字(150个字符)！");
			document.getElementById('mediumName_01').focus();
			msgName = "1";
			return false;
		} 
        
        var url1 = encodeURI(encodeURI('findMediumByMediumNameAction.action?'+new Date() +'&mediumName='+$.trim(mediumName)));	
		$.ajax({
               	url:url1,
               	async:false,
               	datatype: "json",
               	error : function() {   
			    	alert('服务器异常！');
			    	window.location.href="toErrorAction.action";
				}, 	  
               	success : function(data) { 
            		if(data.message =="error"){
				alert("刊例名称重复！");
				msgName = "1";
			}
			if(data.message =="success"){
				msgName = "2";
			}
         }    
       }); 
		
		if(exist("mediumPrice")){
			if($.trim($("#mediumPrice").val())==""){
				alert("刊例价不能为空！");
				document.getElementById("mediumPrice").focus();
		        mediumPriceAlert = "1";
		        return false;
			}else if (pattern.test($("#mediumPrice").val())) {
		        alert("刊例价只能输入数字！");
		        document.getElementById("mediumPrice").focus();
		        mediumPriceAlert = "1";
		        return false;
			}else{
				mediumPriceAlert = "2";
			}
		}
		
		if(exist("mediumAbility")){
			if($("#mediumAbility").val() ==""){
				alert("刊例能力不能为空！");
				mediumAbilityAlert = "1";
				return false;
			}else if(pattern.test($("#mediumAbility").val())) {
		        alert("刊例能力只能输入数字！");
		        document.getElementById("mediumAbility").focus();
		        mediumAbilityAlert = "1";
				return false;
			}else if($("#mediumAbility").val() - 255>0){
				alert("刊例能力不能大于255！");
				document.getElementById("mediumAbility").focus();
				mediumAbilityAlert = "1";
				return false;
			}else{
				mediumAbilityAlert = "2";
			}
		}
		
		if(exist("surchargesRatio")){
			if(!num.test($("#surchargesRatio").val())){
				alert("加收比率只能输入数字！");
				document.getElementById("surchargesRatio").focus();
				surchargesRatioAlert = "2";
				return false;
			}else if($("#surchargesRatio").val()-100 > 0 || $("#surchargesRatio").val()<0){
				alert("加收比率应大于0小于100的整数！");
				document.getElementById("surchargesRatio").focus();
				surchargesRatioAlert = "2";
				return false;
			}else{
				msgAlert = "2";
			}
		}
		
		for(var i=1;i<=9;i++){
			var extAttributeId = "extAttribute0"+i;
			var extAttributeIdVal = $("#extAttribute0"+i).val();
			var extAttributeType = $("#extAttribute0"+i+"Type").val();
			var extAttributeName = $("#extAttribute0"+i+"Name").val();
			if(exist(extAttributeId)){
			if(extAttributeType == "1"){
				if(pattern.test(extAttributeIdVal)){
				alert(extAttributeName+"只能输入数字！");
				document.getElementById(extAttributeId).focus();
				msgAlert = "1";
				return false;
				break;
			}else if(getLen(extAttributeIdVal) > 240){
				alert(extAttributeName+"应不大于80个汉字(240个字符)！");
					document.getElementById(extAttributeId).focus();
					msgAlert = "1";
					return false;
					break;
				}else{
					msgAlert = "2";
				}
			}
		}
		}
		
		for(var i=0;i<=9;i++){
			var extAttributeId = "extAttribute1"+i;
			var extAttributeIdVal = $("#extAttribute1"+i).val();
			var extAttributeType = $("#extAttribute1"+i+"Type").val();
			var extAttributeName = $("#extAttribute1"+i+"Name").val();
			if(exist(extAttributeId)){
			if(extAttributeType == "1"){
				if(pattern.test(extAttributeIdVal)){
				alert(extAttributeName+"只能输入数字！");
				document.getElementById(extAttributeId).focus();
				msgAlert = "1";
				return false;
				break;
			}else if(getLen(extAttributeIdVal) > 240){
				alert(extAttributeName+"应不大于80个汉字(240个字符)！");
					document.getElementById(extAttributeId).focus();
					msgAlert = "1";
					return false;
					break;
				}else{
					msgAlert = "2";
				}
			}
		}
		}
		
		if(exist("extAttribute20")){
			if($("#extAttribute20").val() == "1"){
				if(pattern.test(extAttributeIdVal)){
				alert($("#extAttribute20Name").val()+"只能输入数字！");
				document.getElementById("extAttribute20").focus();
				msgAlert = "1";
				return false;
			}else if(getLen(extAttributeIdVal) > 240){
				alert($("#extAttribute20Name").val()+"应不大于80个汉字(240个字符)！");
					document.getElementById("extAttribute20").focus();
					msgAlert = "1";
					return false;
				}else{
					msgAlert = "2";
				}
			}
		}
		
		if(getLen($("#mediumDescription").val()) > 240){
				alert("简要介绍应不大于80个汉字(240个字符)！");
					document.getElementById("mediumDescription").focus();
					msgAlert = "1";
					return false;
				}else{
					msgAlert = "2";
				}
		
		if(msgName == "2" && msgAlert == "2" && mediumAbilityAlert=="2" && mediumPriceAlert=="2" &&surchargesRatioAlert=="2"){
			var mediumName_001 = $.trim($("#mediumName_01").val());
			$("#mediumName_01").val(mediumName_001);
			document.forms[0].action=url;
			document.forms[0].submit();
		}
	}
</script>

<script type="text/javascript">
	function doSubmit(url){
		document.forms[0].action=url;
		document.forms[0].submit();
	}
	
	function doQuXiao(){
		if(confirm('您确认取消本次操作？')){
			history.go(-1);
		}
	}
	
</script>
	</head>
<body>
<script type="text/javascript">
	$(function(){
        //selectNav('nav2');
    });
</script>
<!-- 顶栏start -->
<jsp:include page="../common/top.jsp"></jsp:include>
<!-- 顶部end -->

<!-- 顶部start -->
<div id="main">
	<div class="body">
	<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<div class="main_body">
				<form action="#" id="form1" method="post">
					<div id="add_div">
						<span style="color:red">${msg}</span>
							<input type="hidden" name="medium.priceID" value="${priceID}"/>
							<input type="hidden" name="priceID" value="${priceID}"/>
							<input type="hidden" id="mediaID" name="mediaID" value="${mediaID}" />
							<input type="hidden" name="contractYear" value="${contractYear}" />
							<input type="hidden" name="mediaType1" value="${mediaType1}" />
						<table class="table_add" style="width: 100%;">
							<tr>
								<th style="width: 155px;">
									刊例名称：
									
								</th>
								<td style="width: 225px;">
									<input id="mediumName_01" name="medium.mediumName" type="text" class="text" style="width: 225px;" maxlength="150"/>
									
									<input id="mediumID_01" name="medium.mediumID" value="00001" type="hidden" class="text"
										style="width: 225px;" maxlength="15"/>
								</td>
								<td style="width: 200px;">
									<div id="mediumName_01Tip" style="width:150px"><span style="color:red">*</span></div>
								</td>
								<th style="width: 155px;">
									媒体类型：
								</th>
								<td style="width: 225px;">
									<s:iterator id="mtl" value="mediaTypeList">
											<c:if test="${mediaType1 eq mtl.id}">
												<input type="text" class="text" style="width: 225px;" value="${mtl.datavalue}" readonly="readonly"/>
											</c:if>
										</s:iterator>
									<input type="hidden" name="medium.mediaType" value="${mediaType1}"/>
									<input name="medium.mediaID" value="${mediaID}" type="hidden" class="text" style="width: 225px;" readonly="readonly" />
								</td>
								<td style="width: 200px;">
									&nbsp;
								</td>
							</tr>
								<tr>
								<th>
									刊例能力：
								</th>
								<td>
									<input type="text" id="mediumAbility" class="text" maxlength="10" style="width: 225px;" name="medium.mediumAbility"/>
								</td>
								<td>
									<div id="mediumAbilityTip" style="width:150px"><span style="color:red">*</span></div>
								</td>
								<th>
									年度：
								</th>
								<td>
									<input name="medium.contractYear" type="text" class="text"
										style="width: 225px;" value="${contractYear}" readonly="readonly"/>
								</td>
								<td>
									&nbsp;
								</td>
							</tr>
							<tr>
								<th>
									刊例赠送类型：
								</th>
								<td>
									<s:select name="medium.mediumPromotionType" list="mediumPromotionTypeList" cssStyle="width:225px;" listKey="id" listValue="datavalue"></s:select>
								</td>
								<td>
									&nbsp;
								</td>
								<th>
									刊例价(元)：
								</th>
								<td>
									<input type="text" id="mediumPrice" maxlength="9" class="text" style="width: 225px;" name="medium.mediumPrice"/>
								</td>
								<td>
									<div id="mediumPriceTip" style="width:150px"><span style="color:red">*</span></div>
								</td>
							</tr>
							<tr>
								<th>
									上画时长：
								</th>
								<td>
									<input type="text" id="mediumDuration" class="text" maxlength="20" style="width: 225px;" name="medium.mediumDuration"/>
								</td>
								<td>
									<div id="mediumDurationTip" style="width:150px"></div>
								</td>
								<th>
									刊例单位：
								</th>
								<td>
									<input type="text" id="mediumUnit" class="text" maxlength="120" style="width: 225px;" name="medium.mediumUnit"/>
								</td>
								<td>
									<div id="mediumUnitTip" style="width:150px"></div>
								</td>
							</tr>
							<tr>
								<th>
									刊例数量：
								</th>
								<td>
									<input type="text" id="mediumNumber" maxlength="8" class="text" style="width: 225px;" name="medium.mediumNumber"/>
								</td>
								<td>
									<div id="mediumNumberTip" style="width:150px"></div>
								</td>
								<th>
									加收比率：
								</th>
								<td>
									<input type="text" id="surchargesRatio" class="text" maxlength="9" style="width: 225px;" name="medium.surchargesRatio"/>
								</td>
								<td>
									<div id="surchargesRatioTip" style="width:150px"></div>
								</td>
							</tr>
							<s:iterator id="sxl" value="shuXingList" status="i">
											<c:set var="s" value="${fn:trim(sxl.id)}" />
											<c:if test="${(i.index+1)%2==1}">
												<tr>
											</c:if>
											<th style='width:150px;'>${sxl.datavalue}：</th>
											<td style='width: 225px;'><input id='${fn:trim(sxl.id)}' name='medium.${fn:trim(sxl.id)}' type='text' class='text' style='width:225px;'  maxlength='100'/></td>
											<td style='width: 200px;'>
												<div id='${fn:trim(sxl.id)}Tip' style='width:150px'><!--  ${fn:trim(sxl.id)}--></div>
												<input type="hidden" id="${fn:trim(sxl.id)}Name" value="${sxl.datavalue}"/>
												<input type="hidden" id="${fn:trim(sxl.id)}Type" value="${sxl.extAttr1}"/>
											</td>
											<c:if test="${(i.index+1)%2==0}">
												</tr>
											</c:if>
										</s:iterator>
								<tr>
								<th>
									简要介绍：
								</th>
								<td  colspan="4">
									<textarea id="mediumDescription" name="medium.mediumDescription" 
										style="width: 647px; font-family: '微软雅黑'; font-size: 12px; font-weight: bold; color: #666666;text-align: left;"></textarea>
								</td>
								<td>
									<div id="mediumDescriptionTip" style="width:150px"></div>
								</td>
								</tr>
						</table>
					</div>
					<div style="margin: 8px 0 0 150px;">
						<input type="button" class="btn-title" value="保存并继续添加" onclick="return doAdd('doAddMediumAction.action?falg=2');"/>
						&nbsp;&nbsp;
						<input type="button" class="btn-title" value="保存" onclick="return doAdd('doAddMediumAction.action?falg=1');"/>
						&nbsp;&nbsp;
						<input type="button" class="btn-title" value="取消" onclick="doQuXiao();"/>
					</div>
				</form>
				</div>
			</div>
		</div>

		<!-- 顶部end -->


		<!-- 底部start -->
		<div id="bottom">
			<div class="body">
				<label>
					版权所有&nbsp;&nbsp;&nbsp;&nbsp;2012东莞移动
				</label>
			</div>
		</div>
		<!-- 底部end -->
	</body>
</html>
